package com.back.controller;

import com.back.common.BaseResponse;
import com.back.common.ResultUtils;
import com.back.exception.ErrorCode;
import com.back.exception.ThrowUtils;
import com.back.model.entity.SceneBase;
import com.back.model.entity.SceneLandmark;
import com.back.service.SceneBaseService;
import com.back.service.SceneLandmarkService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/scene")
public class SceneController {

    @Resource
    private SceneBaseService sceneBaseService;

    @Resource
    private SceneLandmarkService sceneLandmarkService;

    // ==================== 场景相关接口 ====================

    /**
     * 获取所有场景列表（公开接口）
     */
    @GetMapping("/list")
    public BaseResponse<List<SceneBase>> getAllScenes() {
        List<SceneBase> sceneList = sceneBaseService.getAllScenes();
        return ResultUtils.success(sceneList);
    }

    /**
     * 根据场景类型获取场景列表（公开接口）
     */
    @GetMapping("/list/type")
    public BaseResponse<List<SceneBase>> getScenesByType(@RequestParam String sceneType) {
        ThrowUtils.throwIf(sceneType == null || sceneType.trim().isEmpty(), ErrorCode.PARAMS_ERROR, "场景类型不能为空");
        List<SceneBase> sceneList = sceneBaseService.getScenesByType(sceneType);
        return ResultUtils.success(sceneList);
    }

    /**
     * 根据场景ID获取场景详情（公开接口）
     */
    @GetMapping("/get/{sceneId}")
    public BaseResponse<SceneBase> getSceneById(@PathVariable String sceneId) {
        ThrowUtils.throwIf(sceneId == null || sceneId.trim().isEmpty(), ErrorCode.PARAMS_ERROR, "场景ID不能为空");
        SceneBase scene = sceneBaseService.getSceneById(sceneId);
        ThrowUtils.throwIf(scene == null, ErrorCode.NOT_FOUND_ERROR, "场景不存在");
        return ResultUtils.success(scene);
    }

    // ==================== 地标相关接口 ====================

    /**
     * 根据场景ID获取地标列表（公开接口）
     */
    @GetMapping("/landmark/list/{sceneId}")
    public BaseResponse<List<SceneLandmark>> getLandmarksBySceneId(@PathVariable String sceneId) {
        ThrowUtils.throwIf(sceneId == null || sceneId.trim().isEmpty(), ErrorCode.PARAMS_ERROR, "场景ID不能为空");
        List<SceneLandmark> landmarkList = sceneLandmarkService.getLandmarksBySceneId(sceneId);
        return ResultUtils.success(landmarkList);
    }

    /**
     * 根据地标ID获取地标详情（公开接口）
     */
    @GetMapping("/landmark/get/{landmarkId}")
    public BaseResponse<SceneLandmark> getLandmarkById(@PathVariable String landmarkId) {
        ThrowUtils.throwIf(landmarkId == null || landmarkId.trim().isEmpty(), ErrorCode.PARAMS_ERROR, "地标ID不能为空");
        SceneLandmark landmark = sceneLandmarkService.getLandmarkById(landmarkId);
        ThrowUtils.throwIf(landmark == null, ErrorCode.NOT_FOUND_ERROR, "地标不存在");
        return ResultUtils.success(landmark);
    }
}